package com.mctuoluo.mappay;

import org.bukkit.*;
import org.bukkit.entity.*;
import java.lang.reflect.*;

public class TitleAPI
{
    public static Class<?> getNMSClass(final String argumen) {
        final String argumen2 = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
        try {
            return Class.forName("net.minecraft.server." + argumen2 + "." + argumen);
        }
        catch (ClassNotFoundException io) {
            return null;
        }
    }
    
    public static void sendPacket(final Player argumen, final Object argumen0) {
        try {
            final Object argumen2 = argumen.getClass().getMethod("getHandle", (Class<?>[])new Class[0]).invoke(argumen, new Object[0]);
            final Object argumen3 = argumen2.getClass().getField("playerConnection").get(argumen2);
            argumen3.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(argumen3, argumen0);
        }
        catch (Exception ex) {}
    }
    
    public static void sendTitle(final Player argumen, final Integer argumen0, final Integer argumen1, final Integer argumen2, final String argumen3, final String argumen4) {
        try {
            if (argumen3 != null) {
                Object argumen5 = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null);
                Object argumen6 = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + argumen3 + "\"}");
                Constructor<?> argumen7 = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
                Object argumen8 = argumen7.newInstance(argumen5, argumen6, argumen0, argumen1, argumen2);
                sendPacket(argumen, argumen8);
                argumen5 = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TITLE").get(null);
                argumen6 = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + argumen3 + "\"}");
                argumen7 = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"));
                argumen8 = argumen7.newInstance(argumen5, argumen6);
                sendPacket(argumen, argumen8);
            }
            if (argumen4 != null) {
                Object argumen5 = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("TIMES").get(null);
                Object argumen9 = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + argumen3 + "\"}");
                Constructor<?> argumen7 = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
                Object argumen10 = argumen7.newInstance(argumen5, argumen9, argumen0, argumen1, argumen2);
                sendPacket(argumen, argumen10);
                argumen5 = getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0].getField("SUBTITLE").get(null);
                argumen9 = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + argumen4 + "\"}");
                argumen7 = getNMSClass("PacketPlayOutTitle").getConstructor(getNMSClass("PacketPlayOutTitle").getDeclaredClasses()[0], getNMSClass("IChatBaseComponent"), Integer.TYPE, Integer.TYPE, Integer.TYPE);
                argumen10 = argumen7.newInstance(argumen5, argumen9, argumen0, argumen1, argumen2);
                sendPacket(argumen, argumen10);
            }
        }
        catch (Exception io) {
            System.out.println("==================================================================");
            System.out.println("THIS IS NOT AN ISSUE WITH MURDERMYSTERY LITE!");
            io.printStackTrace();
            System.out.println("==================================================================");
        }
    }
}
